<template>
  <div class="app-container">
    <div class="fly-card-head">
      <div class="fly-card-head-wrapper">
        <div class="fly-card-head-title">
          <div class="head-title">官网设置</div>
        </div>
      </div>
    </div>
    <div class="fly-card-body">
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <el-form-item label="网站名称" prop="siteName">
          <el-input v-model="form.siteName" placeholder="请输入网站名称" />
        </el-form-item>
        <el-form-item label="Banner广告">
          <el-radio-group v-model="form.showBanner">
            <el-radio
              v-for="dict in showBannerOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="首页模板编号" prop="templateName">
          <el-input v-model="form.templateName" placeholder="请输入首页模板编号" />
        </el-form-item>
        <el-form-item label="PC端的LOGO" prop="logo">
          <el-input v-model="form.logo" placeholder="请输入PC端的LOGO" />
        </el-form-item>
        <el-form-item label="网站标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入网站标题" />
        </el-form-item>
        <el-form-item label="搜索的关键词" prop="keywords">
          <el-input v-model="form.keywords" placeholder="请输入搜索的关键词" />
        </el-form-item>
        <el-form-item label="网站描述" prop="description">
          <el-input v-model="form.description" placeholder="请输入网站描述" />
        </el-form-item>
        <el-form-item label="违禁关键词" prop="sensitiveWord">
          <el-input v-model="form.sensitiveWord" placeholder="请输入违禁关键词" />
        </el-form-item>
        <el-form-item label="网站版权设置" prop="copyright">
          <el-input v-model="form.copyright" placeholder="请输入网站版权设置" />
        </el-form-item>
        <el-form-item label="站点状态">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
  </div>
  </div>
</template>

<script>
import { getSite, updateSite } from "@/api/site/site";
export default {
  name: "Site",
  data() {
    return {
      // Banner广告字典
      showBannerOptions: [],
      // 站点状态字典
      statusOptions: [],

      // 表单参数
      form: {},
      // 表单校验
      rules: {
        siteName: [
          { required: true, message: "网站名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getDicts("sys_normal_disable").then(response => {
      this.showBannerOptions = response.data;
    });
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
    this.getSite();
  },
  methods: {
    /** 获取网站信息 */
    getSite() {
      this.reset();
      getSite().then(response => {
        this.form = response.data;
      });
    },
    // Banner广告字典翻译
    showBannerFormat(row, column) {
      return this.selectDictLabel(this.showBannerOptions, row.showBanner);
    },
    // 站点状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        siteName: undefined,
        showBanner: "0",
        templateName: undefined,
        logo: undefined,
        title: undefined,
        keywords: undefined,
        description: undefined,
        copyright: undefined,
        createTime: undefined,
        updateTime: undefined,
        status: "0",
        deleted: undefined
      };
      this.resetForm("form");
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateSite(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess("修改成功");
              this.open = false;
            } else {
              this.msgError(response.msg);
            }
          });
        }
      });
    }
  }
};
</script>
